package lanou.giftsay_01.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import lanou.giftsay_01.R;
import lanou.giftsay_01.bean.DanpinBean;

/**
 * Created by dllo on 16/8/19.
 */
public class NsgvAdapte extends BaseAdapter {
    private Context context ;
    private DanpinBean danpinBean ;
    private int i ;

    public void setI(int i) {
        this.i = i;
    }


    public int getI() {
        return i;
    }

    public void setDanpinBean(DanpinBean danpinBean) {
        this.danpinBean = danpinBean;
        notifyDataSetChanged();
    }

    public NsgvAdapte(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return  danpinBean != null ?danpinBean.getData().getCategories().get(i).getSubcategories().size() : 0 ;
    }

    @Override
    public Object getItem(int position) {
        return danpinBean.getData().getCategories().get(i).getSubcategories().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_nsgv , parent ,false);
        }
        ImageView iv = (ImageView) convertView.findViewById(R.id.nsgv_iv);
        Picasso.with(context).load(danpinBean.getData().getCategories().get(i).getSubcategories().get(position).getIcon_url()).into(iv);
        TextView tv = (TextView) convertView.findViewById(R.id.tv_nsgv);
        tv.setText(danpinBean.getData().getCategories().get(i).getSubcategories().get(position).getName());

        return convertView;
    }
}
